package com.jinglvhuanjing.app.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.jinglvhuanjing.app.listener.ButtonClickEvent;

public class ButtonView extends AppCompatTextView {
    private static final String TAG = "common";

    public ButtonView(@NonNull Context context) {
        super(context);
    }

    public ButtonView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ButtonView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private String mLabel;
    private String mKey;
    private ButtonClickEvent mButtonClickEvent;

    public void setParamTag(String label, String key) {
        Log.d(TAG, String.format("设置按钮参数标识：LABEL = %s , KEY = %s ", label, key));
        this.mLabel = label;
        this.mKey = key;
        setOnClickListener(v -> {
            if (this.mButtonClickEvent == null) {
                return;
            }
            Log.d(TAG, String.format("按钮点击：LABEL = %s , KEY = %s ", mLabel, mKey));
            this.mButtonClickEvent.buttonClick(this.mLabel, this.mKey);
        });
    }

    public void setButtonClickEvent(ButtonClickEvent buttonClickEvent) {
        this.mButtonClickEvent = buttonClickEvent;
    }
}
